﻿using SKIT.FlurlHttpClient.Wechat.TenpayV3.Settings;
using System.Collections.Concurrent;

namespace AiQiuQuan.Sport.Core.WechatPayV3
{
    /// <summary>
    /// 微信支付V3证书管理器
    /// </summary>
    public interface IWechatPayV3CertificateManagerFactory
    {
        /// <summary>
        /// 获取证书管理器
        /// </summary>
        /// <param name="merchantId">商户号</param>
        CertificateManager Create(string merchantId);
    }

    /// <summary>
    /// 微信支付V3证书管理器
    /// </summary>
    public class WechatPayV3CertificateManagerFactory : IWechatPayV3CertificateManagerFactory
    {
        private readonly ConcurrentDictionary<string, CertificateManager> _dic;

        /// <summary>
        /// ctor
        /// </summary>
        public WechatPayV3CertificateManagerFactory()
        {
            _dic = new ConcurrentDictionary<string, CertificateManager>();
        }

        /// <summary>
        /// 获取证书管理器
        /// </summary>
        /// <param name="merchantId">商户号</param>
        public CertificateManager Create(string merchantId)
        {
            return _dic.GetOrAdd(merchantId, new InMemoryCertificateManager());
        }
    }
}
